$(document).ready(function(){

	$("#businessMoneyTB").css("display","none");
	$("#promptNoneID").css("display","none");
	$(".promptError").hide();
	
     $('input[name="merId"]').focus (function(){
		
		 $(".promptError").hide();
		 $("#businessMoneyDetailsID").addClass("displayStatus");
		 $("#businessMoneyTB table").empty();
		 $("#promptNoneID").css("display","none");

	 });
	
	$('input[name="merId"]').blur(function(){
		
		var merId = $('input[name="merId"]').val();
		
		if(merId == ""){
			
			$(".promptError").show();
			$('input[name="merId"]').addClass("has-error");
			
		}
		
	 });
	
	
	$("#queryBusinessMoneyID").click(function(){
		
		  $("#businessMoneyDetailsID").addClass("displayStatus");
		  var merId = $('input[name="merId"]').val();
		  if(null == merId || merId == "" || merId == undefined){

			  $('input[name="merId"]').addClass("has-error");
			  $(".promptError").show();
			  
				return;
			  
		  }

		  $.localAjax({
				url : "/businessMoney/getBusinessMoneyStatistics",
				data : JSON.stringify(merId),
				dataType : "json",
				type : "POST",
				contentType:'application/json;charset=UTF-8',
		        beforeSend:function () {
		         },
		 		complete:function(data) { 
		 		}, 
				success : function(result) {
					
					$("#businessMoneyTB table").empty();	
					if(!isEmpty(result.businessMoneyStatistics)){
						
						 $("#businessMoneyTB table").append("<tbody></tbody>");
						 $("#businessMoneyTB table tbody").append("<tr></tr>");
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">币种</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">总金额</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">可用余额</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">不可用余额</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">保证金</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">待审核金额</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">已提金额</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">手续费</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">归还手续费</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">拒付金额</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">退款金额</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">处理费</th>');
						 $("#businessMoneyTB table tbody tr:eq(0)").append('<th class="text-center">账面金额</th>');
						 
						 $("#businessMoneyTB table tbody").append("<tr></tr>");
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">CNY</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.amount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.usableAmount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.disabledAmount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.bond +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.auditAmount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.successAmount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.deduct +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.returnDeductAmount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.protestAmount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.refundAmount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.protestChargeAmount +'</td>');
						 $("#businessMoneyTB table tbody tr:eq(1)").append('<td class="text-center">'+ result.businessMoneyStatistics.bookBalance +'</td>');
						 
						 $("#businessMoneyTB").css("display","");
						 $("#promptNoneID").css("display","none");
						 $("#businessMoneyDetailsID").removeClass("displayStatus");

						 
					 }else{
						 
						 $("#promptNoneID").css("display","");
						 
						 
					 }
						     
				}
			});
	 
	 });
	
   function isEmpty(obj) {
	   
		for ( var name in obj ) {
			
		     return false;
		     
		   }
		
		     return true;
		     
	}

});